﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Web;
using System.Text;
using System.Threading.Tasks;
using WCFServiceWebRole1.Services;

namespace WCFServiceWebRole1_Tests
{
    public class User_Rest_Host
    {
        public static string Service_Protocol { get; set; }
        public static int Service_Port { get; set; }
        public static string Service_IP { get; set; }

        public WebServiceHost Host { get; set; }

        static User_Rest_Host()
        {
            Service_Protocol = "http";
            Service_Port = 20000;
            Service_IP = "localhost";
        }

        public Uri BaseAddress
        {
            get { return new Uri(String.Format("{0}://{1}:{2}", Service_Protocol, Service_IP, Service_Port)); }
        }

        public User_Rest_Host StartHost()
        {
            Host = new WebServiceHost(typeof(user), BaseAddress);
            Host.Open();
            return this;
        }

        public Iusers GetProxy()
        {
            var webChannelFactory = new WebChannelFactory<Iusers>(BaseAddress);
            return webChannelFactory.CreateChannel();
        }
        public User_Rest_Host StopHost()
        {
            Host.Close();
            return this;
        }

    }
}
